package com.ssww.dao.impl;

import java.util.List;

import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.ssww.dao.AboutOurDao;
import com.ssww.entity.AboutOur;

/**
 * dao实现
 * 
 * @author
 * 
 */
@SuppressWarnings("unchecked")
@Repository
public class AboutOurDaoImpl extends HibernateDaoSupport implements AboutOurDao {

	@Autowired
	public AboutOurDaoImpl(@Qualifier("sessionFactory") SessionFactory sessionFactory) {
	    setSessionFactory(sessionFactory);
	}

	@Transactional
	public List<AboutOur> getAboutOurList() {
		String hql = "select * from aboutOur";
		SessionFactory sf = this.getSessionFactory();
		Session session = sf.openSession();
		SQLQuery query = session.createSQLQuery(hql);
		query.addEntity(AboutOur.class);
		return (List<AboutOur>) query.list();
	}

	@Transactional
	public int addAboutOur(AboutOur a) {
		this.getHibernateTemplate().save(a);
		return 0;
	}

	@Transactional
	public int deleteAboutOur(int id) {
		AboutOur a = this.getHibernateTemplate().get(AboutOur.class, id);
		this.getHibernateTemplate().delete(a);
		return 0;
	}

	@Transactional
	public int updateAboutOur(AboutOur a, int id) {
		AboutOur c = this.getHibernateTemplate().get(AboutOur.class, id);
		this.getHibernateTemplate().update(c);
		return 0;
	}

	@Transactional
	public AboutOur getAboutOurById(Integer id) {
		return this.getHibernateTemplate().get(AboutOur.class, id);
	}

}
